package zombiedefense.effects;

import java.awt.Graphics2D;
import java.util.Random;
import zombiedefense.framework.GameObject;
import zombiedefense.framework.PlayerManager;
import zombiedefense.util.MathEx;
import zombiedefense.util.Poolable;
import zombiedefense.map.TileMap;
import zombiedefense.util.Timer;


public abstract class Effect extends Poolable implements GameObject{
	protected static final Random r = MathEx.getRandom();
	protected double x,y;
	private Timer effectTimer;
        protected boolean expired = false;
	private static final int effectZ = 3;
	protected static PlayerManager player;
	
	//initialize timer
	public Effect(){
	    effectTimer = new Timer();
	}
	
	public Effect(double x,double y,long effectTime){
	    this.x = x;
	    this.y = y;
	    effectTimer = new Timer(effectTime);
	}
	
	public abstract void draw(Graphics2D g,int drawx,int drawy,TileMap map);
	
	public void update(long elapsedTime){
	    //start timer
	    if(!effectTimer.isStarted()){
		effectTimer.start();
		effectTimer.reset();
	    }
	    
	    if(effectTimer.hasTicked()){
		expire();
	    }else{
		effectTimer.update(elapsedTime);
	    }
	}
	
	//delete this object if the effect is over
	public boolean isExpired(){
	    return expired;
	}
	
	public void expire(){
	    expired = true;
	    inUse = false;
	}
	
	public void reset(){
	    super.reset();
	    effectTimer.stop();
	    effectTimer.reset();
	    expired = false;
	}
	
	public double getX(){
	    return x;
	}
	
	public double getY(){
	    return y;
	}
	
	public int getWidth(){
	    return 0;
	}
	
	public int getHeight(){
	    return 0;
	}
	
	public int getZ(){
	    return effectZ;
	}
	
	public boolean isOffScreen(int swidth,int sheight,int drawx,int drawy){
	    return false;
	}
	
	public void setFields(double x,double y,long effectTime){
	    this.x = x;
	    this.y = y;
	    effectTimer.setInterval(effectTime);
	}
	
	public static void setPlayer(PlayerManager p){
	    player = p;
	}
    }